//
// Created by WenDaojiang on 15/11/22.
// Copyright (c) 2015 文道江. All rights reserved.
//
#import <AFNetworking/AFNetworking.h>
#import <AFNetworking/UIKit+AFNetworking.h>

@interface URLSessionManager : AFURLSessionManager

+ (URLSessionManager *)defaultManager;

+ (URLSessionManager *)manager;

+ (NSMutableURLRequest *)createRequestWithURL:(NSURL *)url;

+ (NSMutableURLRequest *)createRequestWithURLString:(NSString *)url;

+ (NSURLSessionDataTask *)dataTaskWithURL:(NSURL *)url completionHandler:(void (^)(NSURLResponse *, id, NSError *))completionHandler;

+ (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSURLRequest *)request
                                             progress:(NSProgress * __autoreleasing *)progress
                                          destination:(NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination
                                    completionHandler:(void (^)(NSURLResponse *response, NSURL *filePath, NSError *error))completionHandler;

+ (NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData *)resumeData
                                                progress:(NSProgress * __autoreleasing *)progress
                                             destination:(NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination
                                       completionHandler:(void (^)(NSURLResponse *response, NSURL *filePath, NSError *error))completionHandler;
+ (NSURLSessionUploadTask *)uploadTaskWithStreamedRequest:(NSURLRequest *)request
                                                 progress:(NSProgress * __autoreleasing *)progress
                                        completionHandler:(void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler;
+ (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request
                                         fromData:(NSData *)bodyData
                                         progress:(NSProgress * __autoreleasing *)progress
                                completionHandler:(void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler;
+ (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request
                                         fromFile:(NSURL *)fileURL
                                         progress:(NSProgress * __autoreleasing *)progress
                                completionHandler:(void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler;
#pragma mark - ajax

+ (NSURLSessionDataTask *)ajax:(NSString *)method
                           url:(NSURL *)url
                      dataType:(NSString *)dataType
                        params:(NSDictionary *)params
                    completion:(void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler;

+ (NSURLSessionDataTask *)ajax:(NSString *)method
                           url:(NSURL *)url
                      dataType:(NSString *)dataType
                        params:(NSDictionary *)params
             completionHandler:(void (^)(NSDictionary *data, NSError *error))completionHandler;

+ (NSURLSessionDataTask *)ajax:(NSString *)method
                           url:(NSURL *)url
                        params:(NSDictionary *)params
             completionHandler:(void(^)(NSDictionary *data, NSError *error))completionHandler;

+ (NSURLSessionDataTask *)ajaxPOST:(NSString *)url
                            params:(NSDictionary *)params
                 completionHandler:(void(^)(NSDictionary *data, NSError *error))completionHandler;

+ (NSURLSessionDataTask *)ajaxGET:(NSString *)url
                            params:(NSDictionary *)params
                 completionHandler:(void(^)(NSDictionary *data, NSError *error))completionHandler;

#pragma mark -

+ (NSProgress *)uploadProgressForTask:(NSURLSessionUploadTask *)uploadTask ;

+ (NSProgress *)downloadProgressForTask:(NSURLSessionDownloadTask *)downloadTask ;

#pragma mark -

- (NSMutableURLRequest *)createRequestWithURL:(NSURL *)url;

- (NSURLSessionDataTask *)dataTaskWithURL:(NSURL *)url completionHandler:(void (^)(NSURLResponse *, id, NSError *))completionHandler;

@end

@interface NSDictionary (UrlEncoding)

-(NSString*) urlEncodedString;

@end

@interface NSString (UrlEncoding)

-(NSString*) urlEncodedString;

-(NSString*) urlDecodedString;

@end

@interface URLUtils : NSObject
+ (NSString*) fileMIMEType:(NSString*) file;
+ (NSString *)getMIMEType:(NSString *)ext;
@end